<?php
class RedCard extends MySQLCN {

    function Add() {
	
	$current_date = date("y-m-d");
	//$current_date1 = $this->convertDate($current_date);
	
        $qry = "INSERT INTO `redcard_details` 
            ( `uid`, `card_type`, `total_count`, `reason_for`, `issued_dt`, `issued_by`) 
            VALUES 
            ( '{$_POST['uid']}', '{$_POST['cardtype']}', '{$_POST['totcnt']}', 
              '{$_POST['message']}', '{$current_date}', '{$_POST['empid']}')";
			  
         $this->insert($qry);

    }
	

    function Update($EmpID) {
        $check = $this->get($EmpID);
        if ($check == NULL) {
            return false;
        }
        $qry = "UPDATE `redcard_details` SET
              `uid` = '{$_POST['uid']}', 
              `card_type` = '{$_POST['cardtype']}', 
              `total_count` = '{$_POST['totcnt']}',
              `reason_for` = '{$_POST['message']}'
			   WHERE redcard_id = '{$EmpID}'";
        return $this->insert($qry);
    }

    function Delete($EmpID) {
        $qry = "DELETE FROM `redcard_details` WHERE redcard_id = '{$EmpID}'";
        return $this->insert($qry);
    }

    function get($RCID) {
        $qry = "SELECT * 
                FROM `redcard_details` WHERE redcard_id = '{$RCID}'";
        return $this->select($qry);
    }

        

    function AllList() {
        $qry = "SELECT red.*,emp.* FROM redcard_details as red INNER JOIN users as emp ON red.uid=emp.id";
        return $this->select($qry);
    }
	
	function getIssuedBy($EmpID) {
        $qry = "SELECT Name 
                FROM `users` WHERE id = '{$EmpID}'";
        return $this->select($qry);
    }
    
}

?>